package ONLINE_EXAM;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.Inet4Address;
import java.util.Deque;
import java.util.LinkedList;

public class shell1 {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str ;
        while ((str= br.readLine())!= null){
            int count = Integer.valueOf(str);
            String string = br.readLine();
            String[] strings = string.split(" ");

            int[] input = new int[count];
            for (int i = 0; i < count; i++) {
               input[i] =  Integer.valueOf(strings[i]);
            }

            StringBuffer sb = new StringBuffer();
            int i= 0;
            int j= count-1;
            while (i<j){
                if (input[i]<input[j]){
                    sb.append(input[i]);
                    i++;
                }else if (input[i]>input[j]){
                    sb.append(input[j]);
                    j--;
                }else {
                    //前后元素相等
                    //中间只有一个元素了 -随便进哪个
                    if (i+1 == j-1){
                        sb.append(input[i]);
                        i++;
                    }else {
                        //多个元素 添加 下次元素更小的那个
                        if (input[i+1]>input[j-1]){
                            sb.append(input[j]);
                            j--;
                        }else {
                            sb.append(input[i]);
                            i++;
                        }
                    }
                }
            }
            sb.append(input[i]);
            System.out.println(sb.toString());

        }
    }
}
